<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body v-dialogDrag width="90%">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="model">
        <el-input v-model="queryParams.model" placeholder="请输入产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品明细" prop="brand">
        <el-input v-model="queryParams.brand" placeholder="请输入产品明细"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading"  @selection-change="handleSelectionChange">
          <el-table-column align="center" type="selection" width="55"/>
          <el-table-column align="center" label="序号" type="index" width="50">
            <template slot-scope="scope">
              <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品编码" align="center" prop="goodsCode"/>
          <el-table-column align="center" label="产品状态" prop="state">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sale_state" :value="scope.row.state"/>
            </template>
          </el-table-column>
          <el-table-column align="center" label="产品名称" prop="goodsName"/>
          <el-table-column align="center" label="产品型号" prop="model"/>
          <!--<el-table-column align="center" label="产品明细" prop="brand"/>-->
          <el-table-column align="center" label="产品单位" prop="unit"/>
          <el-table-column align="center" label="销售单价" prop="goodsUnitPrice"/>
          <el-table-column align="center" label="订单数量" prop="orderCount"/>
          <el-table-column align="center" label="锁定数量" prop="lockCount"/>
          <el-table-column align="center" label="待入库数量" prop="pleaseBuyCount" width="210">
            <template slot-scope="scope">
              <el-input-number v-model="scope.row.pleaseBuyCount"></el-input-number>
            </template>
          </el-table-column>
          <!--<el-table-column align="center" label="巡检单" prop="xunjianFile" width="200">
            <template slot-scope="scope">
              <image-preview :src="scope.row.xunjianFile" height="60px" width="40px"></image-preview>
            </template>
          </el-table-column>-->
          <el-table-column align="center" label="备注" prop="remark"/>
      </el-table>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitDoRuku" v-if="">提交订单</el-button>
      <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>

    import {addAction,deleteAction, getAction, getById} from '@/api/manage'

    export default {
        name: "DoGoodsFormList",
        dicts: ['isdo','sale_state'],
        components: {
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "查看生产产品",
                // 是否显示弹出层
                open: false,
                // 显示搜索条件
                showSearch: true,
                // 表单参数
                form: {},
                proId: "",
                proCode: "",
                proName: "",
                proStatus: "",
                columns: [],
                columnsChose: [],
                total: 0,
                // 表单校验
                rules: {
                },
                queryParams: {
                    pageNum: 1,
                    pageSize: 1000,
                    id: null,
                    code: null,
                    goodsName: null,
                    model: null,
                    isdo: "1",
                    remark: null,
                    projectId: null,
                    //orderByColumn:"isdo",
                    isAsc:"desc"
                },
                url: {
                    list: '/goodsSale/goodsSale/list',
                    getById: '/projectBaseInfo/projectBaseInfo/',
                    insertRuku: '/goodsSale/goodsSale/insertRuku',
                },
            };
        },
        created() {
          this.handleQuery();
        },
        methods: {
            submitDoRuku(){
                let that = this;
                const ids = this.ids;
                if (ids == null || ids == '' || ids == 'undefined') {
                  that.$modal.msgError("请选择一条记录");
                } else {
                  that.$refs["form"].validate(valid => {
                    if (valid) {
                      const goodsOrderIn = Object.assign({});
                      goodsOrderIn.projectId=that.proId;
                      goodsOrderIn.columnsGoodsSale = that.columnsChose;
                      addAction(that.url.insertRuku, goodsOrderIn).then(response => {
                        that.$modal.msgSuccess("添加成功");
                         this.open = false;
                        that.$emit('ok');
                        that.getList2();
                        that.handleQuery();
                      });
                    }
                  });
                }
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
              this.ids = selection.map(item => item.id)
              this.single = selection.length !== 1
              this.multiple = !selection.length
              this.columnsChose = selection
            },
            shedingGygx(row){
              this.open = true;
              this.proId=row.id;
              this.getList();
            },
            getList() {
                this.loading = true;
                this.queryParams.projectId = this.proId;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.columns = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
              this.queryParams.pageNum = 1;
              this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
              this.resetForm("queryForm");
              this.handleQuery();
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
          reset() {
            this.form = {
              id: null,
              remark: null,
              delFlag: null,
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null
            };
            this.resetForm("form");
          },
        }
    };
</script>
